package com.acwing.partition21;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author `RKC`
 * @date 2022/5/14 21:54
 */
public class AC2012一排奶牛 {

    private static final int N = 1010;
    private static Set<Integer> set = new HashSet<>(N);
    private static int[] p = new int[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) {
            p[i] = nextInt();
            set.add(p[i]);
        }
        int ans = 0;
        for (int val : set) {
            int res = resolve(val);
            ans = Math.max(ans, res);
        }
        writer.println(ans);
        writer.flush();
    }

    private static int resolve(int del) {
        int res = 0;
        for (int i = 0; i < n; ) {
            int j = i + 1, cnt = 0;
            while (j < n && (p[i] == p[j] || p[j] == del)) {
                if (p[j] == del) cnt++;
                j++;
            }
            res = Math.max(res, j - i - cnt);
            i = j;
        }
        return res;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
